package com.xs;

import java.time.ZoneId;
import java.time.ZonedDateTime;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpMethod;

@SpringBootApplication
@EnableDiscoveryClient
public class GatewayApplication {

	public static void main(String[] args) {
		SpringApplication.run(GatewayApplication.class, args);
	}

	@Bean
	public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
		return builder.routes()
				.route("user_path_route", r -> r.path("/getUser").uri("http://localhost"))
				.route("order_path_route", r -> r.path("/getOrders").uri("http://localhost"))
				.route("order_path_route", r -> r.path("/hello")
						.and().after(ZonedDateTime.of(2019, 4, 1,0, 0, 0, 0, ZoneId.of("+8")))
						//.and().cookie("userName", "aaa")
						//.and().query("userName", "aaa")
						//.and().header("userName", "aaa")
						//.and().host("127.0.0.1")
						//.and().method(HttpMethod.GET)
						.filters(f ->f.addResponseHeader("resHeader", "aaaa").addRequestParameter("age", "18")/*.redirect(302, "http://www.baidu.com")*/)
						
						.uri("http://localhost:8080"))
				.build();
	}
}
